<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Pc_Api_V2_Visa extends Controller_Pc_Api_v2_Base
{
    // 数据请求结果
    private $result;

    /**
     * 参数验证对象
     * @var Request_Api_V2_Visa
     */
    private $validation;

    /**
     * 签证服务
     * @var Service_Api_Visa
     */
    private $service;

    public function before()
    {
        parent::before();
        $this->result = array(
            'status' => true,
            'msg' => '操作成功',
            'data' => array()
        );
        $this->validation = Request_Api_V2_Factory::create('visa', $this->request_params);
        $this->service = new Service_Api_visa();
    }
    public function after()
    {
        $this->send_datagrams($this->client_info['id'], $this->result, $this->client_info['secret_key']);
    }

    // 热门签证国家
    public function action_get_hot_visa_country()
    {
        try {
            $data = $this->service->get_hot_visa_country();
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    //热门签证
    public function action_get_visa_list()
    {
        try {
            $this->validation->get_visa_list()->check();
            $page = $this->request_params['page'] ? $this->request_params['page'] : 1;
            $pagesize = $this->request_params['pagesize'] ? $this->request_params['pagesize'] : 10;
            $data = $this->service->get_visa_by_order($page, $pagesize);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }

    }

    //查询条件
    public function action_get_query_condition()
    {
        try {
            $data = $this->service->query_condition();
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    //签证查询列表
    public function action_get_general_query()
    {
        try {
            $this->validation->get_general_query()->check();
            $data = $this->service->search($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }


    }

    //签证详细
    public function action_get_detail()
    {
        try {
            $this->validation->get_detail()->check();
            $data = $this->service->info($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    //添加订单
    public function action_add_order()
    {
        try {
            $this->validation->add_order()->check();

            $this->request_params['member_info'] = $this->member_info;
            $data = $this->service->create_order($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }
}